// Copyright 2012 Square, Inc.

package com.android.support.jhf.timessquare;

import java.util.Date;

import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;

import com.android.support.jhf.R;
import com.android.support.jhf.timessquare.CalendarPickerView.SelectionMode;

/** Describes the state of a particular date cell in a {@link MonthView}. */
public class MonthCellDescriptor {
	public enum RangeState {
		NONE, FIRST, MIDDLE, LAST
	}

	private SelectionMode selectionMode;
	private final Date date;
	private SpannableString firstSpannableString;
	private SpannableString lastSpannableString;
	private SpannableString value;
	private SpannableString tempValue;
	private final boolean isCurrentMonth;
	private boolean isSelected;
	private final boolean isToday;
	private final boolean isSelectable;
	private boolean isHighlighted;
	private RangeState rangeState;
	private CalendarCellView calendarCellView;

	MonthCellDescriptor(Date date, boolean currentMonth, boolean selectable,
			boolean selected, boolean today, boolean highlighted,
			SpannableString value, RangeState rangeState, SelectionMode mode,
			SpannableString firstSpannableString,
			SpannableString lastSpannableString) {
		this.date = date;
		isCurrentMonth = currentMonth;
		isSelectable = selectable;
		isHighlighted = highlighted;
		isSelected = selected;
		isToday = today;
		this.value = value;
		tempValue = value;
		this.rangeState = rangeState;
		selectionMode = mode;
		this.firstSpannableString = firstSpannableString;
		this.lastSpannableString = lastSpannableString;
	}

	public SelectionMode getSelectionMode() {
		return selectionMode;
	}

	public void setSelectionMode(SelectionMode selectionMode) {
		this.selectionMode = selectionMode;
	}

	public Date getDate() {
		return date;
	}

	public boolean isCurrentMonth() {
		return isCurrentMonth;
	}

	public boolean isSelectable() {
		return isSelectable;
	}

	public boolean isSelected() {
		return isSelected;
	}

	public void setSelected(boolean selected) {
		isSelected = selected;
	}

	boolean isHighlighted() {
		return isHighlighted;
	}

	void setHighlighted(boolean highlighted) {
		isHighlighted = highlighted;
	}

	public boolean isToday() {
		return isToday;
	}

	public RangeState getRangeState() {
		return rangeState;
	}

	public void setRangeState(RangeState rangeState) {
		this.rangeState = rangeState;
	}

	public CalendarCellView getCalendarCellView() {
		return calendarCellView;
	}

	public void setCalendarCellView(CalendarCellView calendarCellView) {
		this.calendarCellView = calendarCellView;
	}

	public void setValue(SpannableString value) {
		this.value = value;
	}

	public SpannableString getValue() {
		if (rangeState == RangeState.FIRST && null != firstSpannableString) {
			String firstString = firstSpannableString.toString();
			String valueString1 = tempValue + firstString;
			SpannableString spannableString1 = new SpannableString(valueString1);
			float moneySize = 12;
			spannableString1.setSpan(new AbsoluteSizeSpan((int) moneySize),
					valueString1.length() - firstString.length() + 1,
					valueString1.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			return spannableString1;
		} else if (rangeState == RangeState.LAST && null != lastSpannableString) {
			String lastString = firstSpannableString.toString();
			String valueString1 = tempValue + lastSpannableString.toString();
			SpannableString spannableString1 = new SpannableString(valueString1);
			float moneySize = 12;
			spannableString1.setSpan(new AbsoluteSizeSpan((int) moneySize),
					valueString1.length() - lastString.length() + 1,
					valueString1.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			return spannableString1;
		}
		return value;
	}

	public void setTempValue(SpannableString tempValue) {
		this.tempValue = tempValue;
	}

	public SpannableString getTempValue() {
		return tempValue;
	}

	@Override
	public String toString() {
		return "MonthCellDescriptor{" + "date=" + date + ", value=" + value
				+ ", isCurrentMonth=" + isCurrentMonth + ", isSelected="
				+ isSelected + ", isToday=" + isToday + ", isSelectable="
				+ isSelectable + ", isHighlighted=" + isHighlighted
				+ ", rangeState=" + rangeState + '}';
	}
}
